﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Lib
{
    public class FileProccess
    {
        public static byte[] FileToBin(string fName)
        {
            FileInfo fInfo = new FileInfo(fName);
            FileStream fStream = new FileStream(fName, FileMode.Open, FileAccess.Read);
            BinaryReader bReader = new BinaryReader(fStream);
            long  numBytes = fInfo.Length;
            //bReader.Close();
            //fStream.Close();
            return bReader.ReadBytes(int.Parse(numBytes.ToString()));
            //hinh.Save(vungnho, System.Drawing.Imaging.ImageFormat.Tiff);  
        }
        public static void BinToFile(byte[]bin,string fName)
        {
            FileStream fStream = new FileStream(
                StringProccess.RemoveUnicode(fName), FileMode.OpenOrCreate, FileAccess.Write);
            
            //BinaryWriter bWriter = new BinaryWriter(fStream);
            fStream.Write(bin, 0, bin.Length);
            fStream.Close();
        }
    }
}
